﻿Public Class frmClientes
    Dim objcontrole As New ClsControle
    Dim objCliente As New CLSClientes
    Dim novo As Boolean

  

    Private Sub frmClientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objcontrole.Habilitar_tela(Me, False)
        objcontrole.Habilitar_botoes(Me, True)
        btnAlterar.Enabled = False
        btnExcluir.Enabled = False
        'BtnImp.Enabled = False

    End Sub

    Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click
        If Not objcontrole.Testar_vazio(Me) Then

            If MskTelefone.Text = "(   )    -" Then
                MessageBox.Show("Digite o telefone")
                MskTelefone.Focus()
            End If

            If MskCPF.Text = "   -   -   -" Then
                MessageBox.Show("Digite o CPF")
                MskCPF.Focus()
                Return
            End If

            If Not objcontrole.Validacombo(cboSitCred) Then
                If (cboSitCred.SelectedItem = "Sim") Then
                    objCliente.Crédito = True
                Else
                    objCliente.Crédito = False
                End If
            End If

            objCliente.Nome = txtNome.Text
            objCliente.CPF = MskCPF.Text
            objCliente.RG = txtRG.Text
            objCliente.Endereço = txtEnd.Text
            objCliente.Bairro = txtBairro.Text
            objCliente.Numero = txtNumero.Text
            objCliente.Telefone = MskTelefone.Text

            novo = True
            objCliente.Gravar(novo)
            MessageBox.Show("Dados do cliente salvo com Sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            objcontrole.Limpar_tela(Me)
            objcontrole.Habilitar_botoes(Me, True)
            'objcontrole.Habilitar_tela(Me, False)
        End If


    End Sub

    Private Sub BTNPRI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNPRI.Click
        objCliente.Ir_para_primeiro()
        Call mostrar_dados_na_tela()
    End Sub


    Private Sub BTNANT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNANT.Click

    End Sub

    Private Sub BTNPRO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNPRO.Click

    End Sub

    Private Sub BTNULT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNULT.Click

    End Sub


    Private Sub mostrar_dados_na_tela()
        txtCod.Text = objCliente.ID
        txtNome.Text = objCliente.Nome
        txtEnd.Text = objCliente.Endereço
        txtBairro.Text = objCliente.Bairro
        MskTelefone.Text = objCliente.Telefone()
        cboSitCred.SelectedValue = objCliente.Crédito()
        txtNumero.Text = objCliente.Numero
        MskCPF.Text = objCliente.CPF()
        txtRG.Text = objCliente.RG
        btnAlterar.Enabled = True
        btnExcluir.Enabled = True
        'BtnImp.Enabled = True
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Call frmClientes_Load(Nothing, Nothing)
        objcontrole.Limpar_tela(Me)
    End Sub

    Private Sub btnExcluir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcluir.Click
        If objCliente.excluir(txtCod.Text) Then
            objcontrole.Limpar_tela(Me)
        End If
    End Sub

    Private Sub btnAlterar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlterar.Click
        objcontrole.Habilitar_tela(Me, True)
        objcontrole.Habilitar_botoes(Me, False)
        txtCod.Enabled = False
        txtNome.Focus()
        novo = False
    End Sub

    Private Sub btnNovo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNovo.Click
        objcontrole.Limpar_tela(Me)
        objcontrole.Habilitar_tela(Me, True)
        objcontrole.Habilitar_botoes(Me, False)
        txtCod.Enabled = False
        btnCancelar.Enabled = True
        btnSalvar.Enabled = True
        txtNome.Focus()
        novo = True
    End Sub

    Private Sub btnCancelar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click

    End Sub
End Class